﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChartTools
{
    /// <summary>
    /// 柱状折线图
    /// </summary>
    public class Col3DLineDY3
    {
        private string data;
        /// <summary>
        /// 获取曲线json数据
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return data;
        }
        private Col3DLineDY3() { }
        /// <summary>
        /// 不带JS回调方法
        /// </summary>
        /// <param name="pData"></param>
        /// <param name="pFunctionName"></param>
        /// <param name="pShowDivID"></param>
        /// <param name="pTitle"></param>
        public Col3DLineDY3(Col3DLineDY3Data pData, string pFunctionName, string pShowDivID, string pTitle)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<chart caption='" + pTitle + "' XAxisName='' palette='0' animation='1' formatNumberScale='0' numberPrefix='$' showValues='0' seriesNameInToolTip='0' >");
            sb.Append("<categories>");
            foreach (string label in pData.Labels)
            {
                sb.Append("<category label='");
                sb.Append(label);
                sb.Append("' />");
            }
            sb.Append("</categories>");
            sb.Append("<dataset seriesname='");
            sb.Append(pData.ColName);
            sb.Append("'>");
            foreach (decimal label in pData.ColDatas)
            {
                sb.Append("<set value='");
                sb.Append(label);
                sb.Append("' />");
            }
            sb.Append("</dataset>");

            sb.Append("<dataset seriesName='");
            sb.Append(pData.LineName);
            sb.Append("' parentYAxis='S'>");
            foreach (decimal label in pData.LineDatas)
            {
                sb.Append("<set value='");
                sb.Append(label);
                sb.Append("' />");
            }
            sb.Append("<set value='0'  color='   bfbfe3'/>");
            sb.Append("<set value='0'  color='   bfbfe3'/>");
            sb.Append("<set value='0'  color='   bfbfe3' />");
            sb.Append("<set value='30'/>");
            /////////////////////
            //sb.Append("</dataset>");

            //sb.Append("<dataset seriesName='");
            //sb.Append("' parentYAxis='S'>");
            //for (int i = 0; i < pData.LineDatas.Count - 1; i++)
            //{
            //    sb.Append("<set value='");
            //    sb.Append(pData.LineDatas[i]);
            //    sb.Append("'  alpha='0' />");
            //}
            //sb.Append("<set value='");
            //sb.Append(20);
            //sb.Append("'/>");
            //sb.Append("<set value='");
            //sb.Append(80);
            //sb.Append("'/>");
            //sb.Append("<set value='");
            //sb.Append(90);
            //sb.Append("'/>");
            //sb.Append("<set value='");
            //sb.Append(100);
            //sb.Append("'/>");
            //sb.Append("<set value='");
            //sb.Append(120);
            //sb.Append("'/>");
            /////////////////////
            sb.Append("</dataset>");

            //sb.Append("<dataset seriesName='");
            //sb.Append("趋势线");
            //sb.Append("' parentYAxis='S' color='   bfbfe3'>");
            //for (int i = 0; i < pData.LineDatas.Count; i++)
            //{

            //    sb.Append("<set value='");
            //    sb.Append(30 + new Random().Next(3, 30));
            //    sb.Append("' />");
            //}
            //sb.Append("</dataset>");
            ////////////////
            sb.Append("<styles><definition><style type='font' color='000000' name='CaptionFont' size='15' /><style type='font' name='SubCaptionFont' bold='0' /></definition><application><apply toObject='caption' styles='CaptionFont' /><apply toObject='SubCaption' styles='SubCaptionFont' /></application></styles></chart>");
            string datas = sb.ToString();
            sb = new StringBuilder();
            sb.AppendLine("<script type=\"text/javascript\">");
            sb.Append("            function ");
            sb.Append(pFunctionName);
            sb.AppendLine("(){");
            sb.AppendLine("                var chart = new FusionCharts(\"/Content/FusionCharts/MSColumn3DLineDY.swf\", \"ChartId\", \"100%\", \"260\", \"0\", \"0\");");
            sb.AppendLine("                chart.setXMLData(\"" + datas + "\");");
            sb.AppendLine("                chart.render(\"" + pShowDivID + "\");");
            sb.AppendLine("             }");
            sb.AppendLine("        </script>");
            data = sb.ToString();
        }
        /// <summary>
        /// 带JS回调方法
        /// </summary>
        /// <param name="pData"></param>
        /// <param name="pFunctionName"></param>
        /// <param name="pShowDivID"></param>
        /// <param name="pTitle"></param>
        /// <param name="pModth"></param>
        /// <param name="args"></param>
        public Col3DLineDY3(Col3DLineDY3Data pData, string pFunctionName, string pShowDivID, string pTitle, string pModth, string pix)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<chart caption='" + pTitle + "' XAxisName='' palette='0' animation='1' formatNumberScale='0' numberPrefix='" + pix + "' showValues='0' seriesNameInToolTip='0'>");
            sb.Append("<categories>");
            foreach (string label in pData.Labels)
            {
                sb.Append("<category label='");
                sb.Append(label);
                sb.Append("' />");
            }
            sb.Append("</categories>");
            sb.Append("<dataset seriesname='");
            sb.Append(pData.ColName);
            sb.Append("'>");
            for (int i = 0; i < pData.ColDatas.Count; i++)
            {
                sb.Append("<set value='");
                sb.Append(pData.ColDatas[i]);
                sb.Append("' link='j-" + pModth + "-" + pData.Labels[i] + "'/>");
            }
            sb.Append("</dataset>");
            //sb.Append("<dataset seriesName='");
            //sb.Append("趋势线");
            //sb.Append("' parentYAxis='S'>");
            //for (int i = 0; i < pData.LineDatas.Count; i++)
            //{

            //    sb.Append("<set value='");
            //    sb.Append(30 + new Random().Next(3, 30));
            //    sb.Append("' />");
            //}
            //sb.Append("</dataset>");
            if (!string.IsNullOrEmpty(pData.LineName))
            {
                sb.Append("<dataset seriesName='");
                sb.Append(pData.LineName);
                sb.Append("' parentYAxis='S'>");
                foreach (decimal label in pData.LineDatas)
                {
                    sb.Append("<set value='");
                    sb.Append(label);
                    sb.Append("' />");
                }
                sb.Append("</dataset>");
            }
            sb.Append("<styles><definition><style type='font' color='000000' name='CaptionFont' size='15' /><style type='font' name='SubCaptionFont' bold='0' /></definition><application><apply toObject='caption' styles='CaptionFont' /><apply toObject='SubCaption' styles='SubCaptionFont' /></application></styles></chart>");
            string datas = sb.ToString();
            sb = new StringBuilder();
            sb.AppendLine("<script type=\"text/javascript\">");
            sb.Append("            function ");
            sb.Append(pFunctionName);
            sb.AppendLine("(){");
            sb.AppendLine("                var chart = new FusionCharts(\"/Content/FusionCharts/MSColumn3DLineDY.swf\", \"ChartId\", \"100%\", \"260\", \"0\", \"0\");");
            sb.AppendLine("                chart.setXMLData(\"" + datas + "\");");
            sb.AppendLine("                chart.render(\"" + pShowDivID + "\");");
            sb.AppendLine("             }");
            sb.AppendLine("        </script>");
            data = sb.ToString();
        }
    }
    /// <summary>
    /// 3D柱状折线图基本数据类型
    /// </summary>
    public class Col3DLineDY3Data
    {
        /// <summary>
        /// 柱状图含义
        /// </summary>
        public string ColName { get; set; }
        /// <summary>
        /// 折线图含义
        /// </summary>
        public string LineName { get; set; }
        /// <summary>
        /// 柱子数据
        /// </summary>
        public List<double> ColDatas { get; set; }
        /// <summary>
        /// 折线数据
        /// </summary>
        public List<double> LineDatas { get; set; }
        /// <summary>
        /// X轴显示名称
        /// </summary>
        public List<string> Labels { get; set; }
    }
}
